﻿@using Entidades.Sistema.Distribucion
@using Entidades.Sistema.Venta

@{
    Html.EnableClientValidation(true);
    Html.EnableUnobtrusiveJavaScript(true);
    
    var grid =  Html.DevExpress().GridView(
        settings =>
        {
            settings.Name = "masterGrid";
            settings.KeyFieldName = "IdDiagramacionDistribucionDetalle";
            settings.CallbackRouteValues = new { Controller = "DiagramacionDistribucion", Action = "EditDiagramacionDistribucionDetallePartial" };
            
            settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);

            settings.SettingsEditing.BatchUpdateRouteValues = new { Controller = "DiagramacionDistribucion", Action = "EditDiagramacionDistribucionDetalleUpdatePartial" };
            settings.SettingsEditing.Mode = GridViewEditingMode.Batch;

            
            settings.Columns.Add("Empleado.IdEmpleado").ReadOnly = true;
            settings.Columns.Add("Empleado.NombreApellido").ReadOnly = true;

            settings.Columns.Add(
                column =>
                {
                    column.FieldName = "Vehiculo.IdVehiculo";
                    column.Caption = "Vehiculo";

                    column.ColumnType = MVCxGridViewColumnType.ComboBox;
                    var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                    comboBoxProperties.DataSource = ViewBag.Vehiculo;
                    comboBoxProperties.TextField = "Modelo";
                    comboBoxProperties.ValueField = "IdVehiculo";
                    comboBoxProperties.ValueType = typeof(int);
                    comboBoxProperties.DropDownStyle = DropDownStyle.DropDown;
                });
            

            settings.SettingsDetail.AllowOnlyOneMasterRowExpanded = false;
            settings.SettingsDetail.ShowDetailRow = true;

            settings.SetDetailRowTemplateContent(c =>
            {
                Html.RenderAction("PedidosPartial", new { IdDiagramacionDistribucionDetalle = DataBinder.Eval(c.DataItem, "IdDiagramacionDistribucionDetalle") });
            });        
        });

    if (ViewData["EditError"] != null)
    {
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}

@grid.Bind(Model).GetHtml()


